<?php namespace Asset;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;

class AssetCombineCommand extends AssetCommand {
	
	/**
	 * The console command name.
	 *
	 * @var string
	 */
    protected $name = "asset:combine";

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = "Combines multiple resource files.";

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
    	parent::__construct();
    }
    
    /**
     * Execute the console command.
     *
     * @return mixed
     */
    // php artisan asset:combine t/1.css,t/2.css --output=t/a.css
    public function fire()
    {
    	
        $input    = $this->argument("input");
        $output   = $this->option("output");
        
        // The code is merged when the asset is dumped
        $combined = $this->getCollection($input)->dump();

        if ($output) {
            $this->line('<info>Successfully combined</info> <comment>' . $input . '</comment> <info>to</info> <comment>' . $output . '</comment>');
            $this->setOutput($output, $combined);
        } else { 
            $this->line($combined); // output the results to console
        }
    }

    /**
     * Get the console command arguments.
     * The method accepts a comma delimited list of asset files (relative to the public folder)
     *
     * @return array
     */
    protected function getArguments()
    {
        return [
            ["input", InputArgument::REQUIRED, "Comma-delimited names of files to concatenate."]
        ];
    }

    /**
     * Get the console command options.
     * If we want to save the results to a file we can provide the –output option with a path to the combined file.
     *
     * @return array
     */
    protected function getOptions()
    {
        return [
            ['output', null, InputOption::VALUE_OPTIONAL, 'The optional path to save to.', null]
        ];
    }
}